﻿CREATE VIEW [dbo].[vwUniqueUsersPerMonth]
	AS 
   SELECT TOP 100 percent
	A.AppName,
	Year(cast(AA.[StartDateTime] as date)) as [Year],
	Month(cast(AA.[StartDateTime] as date)) as [Month],
    COUNT(DISTINCT [Username]) AS UniqueUsers
  FROM [dbo].[AppAnalytics] AA INNER JOIN [dbo].[App] A ON AA.[AppId] = A.[AppId]
  WHERE
	[HostWebUrl] NOT LIKE 'https://arthurgraus.sharepoint.com%'
  GROUP BY
	A.AppName,
	Year(cast(AA.[StartDateTime] as date)) ,
	Month(cast(AA.[StartDateTime] as date)) 
  ORDER BY
	A.AppName,
	Year(cast(AA.[StartDateTime] as date)) ,
	Month(cast(AA.[StartDateTime] as date))
